#ifndef TCPKERNEL_H
#define TCPKERNEL_H
#include<map>
#include<stdio.h>
#include "IKernel.h"
#include"../mysql/CMySql.h"
#include<QDebug>
#include<list>
#include <QFileInfo>
#include <QFile>
#include <QDir>
#include <QBuffer>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <sys/stat.h> 
#include <sys/types.h> 
struct STRU_FILEINFO{
    long long m_fileId;
    long long m_userId;
    FILE*m_pfile;
    long long m_filesize;
    long long m_pos;

    char m_szFileMD5[33]; // 添加 MD5 成员
};

class TCPKernel : public IKernel
{
private:
    TCPKernel();
    ~TCPKernel();
public:
     bool open(const char*szip="127.0.0.1",short nport =1234);
     void close();
     void dealDate(SOCKET sock,const char*szbuf);
 public:
     void registerrq(SOCKET sock,const char*szbuf);
     void loginrq(SOCKET sock,const char*szbuf);
     void getfilelist_rq(SOCKET sock,const char*szbuf);
     void uploadfileinforq(SOCKET sock,const char*szbuf);
     void uploadfileblockrq(SOCKET sock,const char*szbuf);
     void downloadfileinforq(SOCKET sock,const char*szbuf);
     void downloadfileblockrq(SOCKET sock,const char*szbuf);
     void deletefilerq(SOCKET sock, const char *szbuf);
     // 在 dealDate 函数声明中添加
     void searchfilerq(SOCKET sock, const char *szbuf);
     void renameFile(SOCKET sock, const char *szbuf);
     //void previewrq(SOCKET sock, const char *szbuf);

 public:
     //单例模式：饿汉模式，懒汉模式
     //静态指针
     static IKernel*getKernel(){
         if(!m_pKernel){
             m_pKernel=new TCPKernel;
         }
         return m_pKernel;
     }
 private:
    INet *m_pTCPNet;
    CMySql *m_pSQL;
    static IKernel* m_pKernel;
    char m_szSystemPath[MAX_PATH];
    std::list<STRU_FILEINFO*> m_lstFileINfo;

};

#endif // TCPKERNEL_H
